package com.iyundao.io.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.iyundao.io.Service.IntegralService;
import com.iyundao.io.model.IntegralRecord;
import com.iyundao.io.tools.ResponseData;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "/integral")
public class IntegralController {

    @Autowired
    private IntegralService integralService;

    /**
     *对积分进行增删操作
     */
    @ApiOperation(value="积分变动", notes="积分变动")
    @RequestMapping(value = "/updateIntegral", produces = {"application/json;charset=UTF-8"})
    @CrossOrigin
    public ResponseData IntegralOperation(@RequestBody JSONObject params) {
        IntegralRecord integralRecord = JSON.toJavaObject(params, IntegralRecord.class);
        return integralService.updateIntegralSum(integralRecord);

    }

    @ApiOperation(value="查询个人总积分、现有积分", notes="查询个人总积分、现有积分")
    @RequestMapping(value = "/personalintegral", produces = {"application/json;charset=UTF-8"})
    @CrossOrigin
    public ResponseData PersonalIntegral(@RequestBody JSONObject params) {
        Integer id = JSON.toJavaObject(params, Integer.class);
        return integralService.selectIntegralByPartyMemberId(id);
    }

    @ApiOperation(value="查询个人积分变动记录", notes="查询个人积分变动记录")
    @RequestMapping(value = "/personalintegralrecord", produces = {"application/json;charset=UTF-8"})
    @CrossOrigin
    public PageInfo<IntegralRecord> PersonalIntegralRecord(int currentPage, int pageSize, @RequestBody JSONObject params) {
        Integer id = JSON.toJavaObject(params, Integer.class);
        return integralService.showIntegralRecord(currentPage, pageSize, id);
    }



}
